package com.xiaoke.accountsoft.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.xiaoke.accountsoft.dao.PwdDAO;


/**
 * Created by zhang on 2017/4/28.
 */

public class Login extends AppCompatActivity {
    private TextView txtlogin;
    private TextView btnlogin;
    private TextView btnclse;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        //获取密码文本框
        txtlogin = (EditText) findViewById(R.id.txtLogin);
        //获取登录按钮
        btnlogin = (Button) findViewById(R.id.btnLogin);
        //为登录按钮设置监听
        btnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                //创建Intent对象
                Intent intent = new Intent(Login.this, MainActivity.class);
                //创建PwdDAO对象
                PwdDAO pwdDAO = new PwdDAO(Login.this);
                //判断是否有密码及时否输入了密码
                /*if ((pwdDAO.getCount() == 0 | pwdDAO.find().getPassword().isEmpty())
                        && txtlogin.getText().toString().isEmpty()) {
                    //启动主Activity
                    startActivity(intent);
                }/* else {
                    //判断输入的密码是否与数据库中的一致
                    if (pwdDAO.find().getPassword().equals(txtlogin.getText().toString())) {
                        //启动主Activity
                        startActivity(intent);
                    } else {
                        //弹出信息提示
                        Toast.makeText(Login.this, "请输入正确的密码！", Toast.LENGTH_SHORT).show();
                    }
                }*/
                if (txtlogin.getText().length()!=0)
                    startActivity(intent);
                txtlogin.setText("");
                Login.this.finish();
            }

        });
        btnclse=(Button)findViewById(R.id.btnClose);
        btnclse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                finish();       //退出当前程序

            }
        });

    }
}